package com.yc.zyz.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yc.zyz.entity.Joins;
import com.yc.zyz.mapper.JoinsMapper;
import com.yc.zyz.mapper.TaskMapper;
import com.yc.zyz.util.Utils;
import org.apache.ibatis.session.SqlSession;

import java.util.function.Consumer;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/7/28
 * Email haijunzhou@hnit.edu.cn
 */
public class ZyzBiz {

    public void join(String tid, Integer uid) throws BizException {
        Object ret = Utils.exec(session->{
            JoinsMapper joinsMapper = session.getMapper(JoinsMapper.class);
            LambdaQueryWrapper<Joins> lqw = new LambdaQueryWrapper<>();
            lqw.eq(Joins::getTid, tid);
            lqw.eq(Joins::getUid, uid);
            Integer count = joinsMapper.selectCount(lqw);
            if(count > 0){
                return "该用户已经加入当前活动了";
            }
            Joins joins = new Joins();
            joins.setTid(Integer.valueOf(tid));
            joins.setUid(uid);
            joinsMapper.insert(joins);
            return null;
        });

        if(ret!=null){
            throw new BizException(ret.toString());
        }

    }


}
